/*
 * @Author: szx
 * @Date: 2022-03-14 17:17:34
 * @LastEditTime: 2022-03-14 17:21:39
 * @Description:
 * @FilePath: \leetcode\500-599\599\599.js
 */
/**
 * @param {string[]} list1
 * @param {string[]} list2
 * @return {string[]}
 */
 var findRestaurant = function (list1, list2) {
    const map = new Map();
    for (let i = 0; i < list1.length; i++) {
        map.set(list1[i], i);
    }
    let res = [];
    let min = Infinity;
    for (let i = 0; i < list2.length; i++) {
        if (map.has(list2[i])) {
            const tmp = i + map.get(list2[i]);
            if (tmp < min) {
                min = tmp;
                res = [list2[i]];
            } else if (tmp == min) {
                res.push(list2[i]);
            }
        }
    }
    return res;
};
